
// Popup input Title for 'URL Frame' record
currentDNS = null;
imgStatus = {
	'show'	: 'images/news.gif',
	'ok'	: 'images/yes.gif'
};
function S(id) 
{
	return document.getElementById(id)
}
function ValidPhone($phone)
{
	if($phone.length<7) return false;
	return /^\+?[0-9\-]+$/.test($phone);
}
function ValidMobile($mobile)
{
	if($mobile.length<10) return false;
	return /^0[1|9][0-9]{8,10}$/.test($mobile);
}
function IsValidEmail(email)
{	
   var pattern = /^([a-zA-Z0-9_\.\-])+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   return pattern.test(email);
}
function trim($value)
{
	return $value.replace(/^\s+|\s+$/g,'');
}
function trimall($value)
{
	return $value.replace(/\s+/g,'');
}
function ChangeLayout(view)
{
	window.location = 'index.php?view='+view;
	return false;
}
function Set_Cookie(name,value,expires,path,domain,secure)
{
	var today=new Date();
	var expires_date=new Date(today.getTime()+(expires));
	var cookieString=name+"="+encodeURIComponent(value)+((expires)?";expires="+expires_date.toGMTString():"")+((path)?";path="+path:"")+((domain)?";domain="+domain:"")+((secure)?";secure":"");
	document.cookie=cookieString;
}
function getCookie(Name)
{
	var search=Name+"="
	var CookieString=document.cookie
	var result=null
	if(CookieString.length>0){offset=CookieString.indexOf(search)
	if(offset!=-1){offset+=search.length
	end=CookieString.indexOf(";",offset)
	if(end==-1){end=CookieString.length}
	result=unescape(CookieString.substring(offset,end))}}
	return result;
}
function RemoveUnicode(text)
{
	var unicode =[
	{'key':'a','value':'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ'},
	{'key':'d','value':'đ'},
	{'key':'e','value':'é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ'},
	{'key':'i','value':'í|ì|ỉ|ĩ|ị'},
	{'key':'o','value':'ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ'},
	{'key':'u','value':'ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự'},
	{'key':'y','value':'ý|ỳ|ỷ|ỹ|ỵ'},
	{'key':'A','value':'Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ'},
	{'key':'D','value':'Đ'},
	{'key':'E','value':'É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ'},
	{'key':'I','value':'Í|Ì|Ỉ|Ĩ|Ị'},
	{'key':'O','value':'Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ'},
	{'key':'U','value':'Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự'},
	{'key':'Y','value':'Ý|Ỳ|Ỷ|Ỹ|Ỵ'}
	];					
	for(vars in unicode)
	{						
		text=text.replace(new RegExp ( unicode[vars].value, "g" ),unicode[vars].key);
	}					
	return text;				
}
function copyData(from,to)
{
	alert(from+"|"+to);
	S(to+'FName').value=S(from+'FName').value;
	S(to+'LName').value=S(from+'LName').value;
	S(to+'Organization').value=S(from+'Organization').value;
	S(to+'EmailAddress').value=S(from+'EmailAddress').value;
	S(to+'Address1').value=S(from+'Address1').value;
	if(S(to+'Address2'))
	{
		S(to+'Address2').value=S(from+'Address2').value;
	}
	S(to+'City').value=S(from+'City').value;
	S(to+'StateProvince').value=S(from+'StateProvince').value;
	S(to+'PostalCode').value=S(from+'PostalCode').value;
	S(to+'Country').value=S(from+'Country').value;
	S(to+'Phone').value=S(from+'Phone').value;
	if(S(to+'PhoneExt'))
	{
		S(to+'PhoneExt').value=S(from+'PhoneExt').value;
	}
	S(to+'Fax').value=S(from+'Fax').value;
	if(S(to+'JobTitle'))
	{
		S(to+'JobTitle').value=S(from+'JobTitle').value;
	}
}
function copyData2(from,to)
{
	S(to+'_name').value=S(from+'_name').value;
	S(to+'_company').value=S(from+'_company').value;
	S(to+'_emailaddr').value=S(from+'_emailaddr').value;
	S(to+'_address1').value=S(from+'_address1').value;
	S(to+'_address2').value=S(from+'_address2').value;
	S(to+'_address3').value=S(from+'_address3').value;
	S(to+'_city').value=S(from+'_city').value;
	S(to+'_state').value=S(from+'_state').value;
	S(to+'_country').value=S(from+'_country').value;
	S(to+'_zip').value=S(from+'_zip').value;
	S(to+'_telnocc').value=S(from+'_telnocc').value;
	S(to+'_telno').value=S(from+'_telno').value;
	S(to+'_faxno').value=S(from+'_faxno').value;
}

function copyData3($from,$to)
{
	$("#"+$to+"_name").val($("#"+$from+"_name").val());
	$("#"+$to+"_company").val($("#"+$from+"_company").val());
	$("#"+$to+"_email").val($("#"+$from+"_email").val());
	$("#"+$to+"_address").val($("#"+$from+"_address").val());
	$("#"+$to+"_city").val($("#"+$from+"_city").val());
	$("#"+$to+"_zipcode").val($("#"+$from+"_zipcode").val());
	$("#"+$to+"_country").val($("#"+$from+"_country").val());
	$("#"+$to+"_phone").val($("#"+$from+"_phone").val());
	$("#"+$to+"_fax").val($("#"+$from+"_fax").val());
}
function ChangeTypeDNS(no)
{
	var type 	= S('dnstype_'+no).value;
	var img 	= S('dnsimg_'+no);	
	// Neu la URL Frame thi view nut bam
	if(type==5) 
	{
		if(S('dnstitle_'+no).value=='') img.src = imgStatus['show'];
		else img.src = imgStatus['ok'];
		img.style.display = 'block';
	}else 
	{
		img.style.display = 'none';
	}
	
	var $obj 	= $("select.recordtype[rel='"+no+"']",$("#process_step"));
	var $parent = $obj.parents("tr.record:first");
	
	if($obj.val()==3 || $obj.val()==5)	
	{
		if($("input.address",$parent).val()=='') 
		{
			$("input.address",$parent).val('http://');			
			$("input.host",$parent).focus();
		}
		$("input.priority",$parent).addClass('hide');
		$("input.srv",$parent).addClass('hide');
		$("input.host",$parent).attr("placeholder","");
		$("input.address",$parent).css({"width":"320px"});
	}else if($obj.val()==2)	
	{
		$("input.priority",$parent).removeClass('hide');
		$("input.srv",$parent).addClass('hide');
		if($("input.address",$parent).val()=='http://')
		{
			$("input.address",$parent).val('');
		}
		$("input.address",$parent).css({"width":"320px"});
		$("input.address",$parent).focus();
	}else if($obj.val()==7)
	{
		$("input.priority",$parent).removeClass('hide');
		$("input.srv",$parent).removeClass('hide');
		$("input.host",$parent).attr("placeholder","Service");
		$("input.address",$parent).css({"width":"105px"});
		if($("input.address",$parent).val()=='http://')
		{
			$("input.address",$parent).val('');
		}
	}else
	{		
		$("input.priority",$parent).addClass('hide');
		$("input.srv",$parent).addClass('hide');
		$("input.host",$parent).attr("placeholder","");
		$("input.address",$parent).css({"width":"320px"});
		if($("input.address",$parent).val()=='http://')
		{
			$("input.address",$parent).val('');
		}
	}
}
function ShowPopupDNS(no)
{
	currentDNS = no;	
	
	// Doi trang thai hinh anh
	var img 	= S('dnsimg_'+no);
	if(S('dnstitle_'+no).value=='') img.src = imgStatus['show'];
	else img.src = imgStatus['ok'];
	
	// Lay thong tin co san cap nhat vao popup
	var popup	= S('dns_popup');
	S('dns_title').value 	= S('dnstitle_'+no).value;
	
	// Cap nhat lai vi tri popup
	var top 	= -20;
	var left 	= -150;
	for (; img; img=img.offsetParent){
		top  += img.offsetTop;
		left += img.offsetLeft;
	}	
	popup.style.top 	= top+'px';
	popup.style.left	= left+'px';	
	popup.style.display	= 'block';
	
	var iframe	= S('dns_iframe');
	iframe.style.top 		= top+'px';
	iframe.style.left		= left+'px';	
	iframe.style.display	= 'block';
}
function ClosePopupDNS(update)
{
	if(update==null) update = false;
	if(update && currentDNS!=null){
		S('dnstitle_'+currentDNS).value = S('dns_title').value;
	}
	
	if(currentDNS!=null){
		var img 	= S('dnsimg_'+currentDNS);
		if(S('dnstitle_'+currentDNS).value=='') img.src = imgStatus['show'];
		else img.src = imgStatus['ok'];
	}	
	
	var popup	= S('dns_popup');
	popup.style.display	= 'none';
	
	var iframe	= S('dns_iframe');
	iframe.style.display	= 'none';
}				  
function inputNumber(e)
{
	// cho phep nhap so, nut backspace, delete vau dau .
	var keynum;
	if(window.event){ // IE
	  keynum = e.keyCode;
	}
	else if(e.which){ // Netscape/Firefox/Opera
	  keynum = e.which;
	}
	
	if(((keynum > 45) && (keynum <58)) || ((keynum > 95) && (keynum <106)) || (keynum == 8) || (keynum == 9) || (keynum == 190) || (keynum == 39)|| (keynum == 37) ) return true;
	// 37 : left ; 39: right
	
	return false;
}
function AddRecord($flag)
{
	var $maxrecord = 500;
	ul 		= $('#process_step',document.body);		
	var $numhost = parseInt($("tr.record",$("#process_step")).length);	
	var $n 	= 1;
	if($numhost>$maxrecord)
	{
		alert("Bạn không thể thêm quá nhiều!");
		return false;
	}
	if($numhost+$n>$maxrecord)
	{
		$n 		= $maxrecord - $numhost;
	}
	
	for($i=0;$i<$n;++$i)
	{		
		li 			= ul.children('tbody').children('tr:last');
		step 	= li.clone();
		stt 	= parseInt(step.children('td').children('select').attr('id').replace ('dnstype_','')) + 1;
		step.children('td').children('input.host').attr('name','host'+stt);
		step.children('td').children('input.IDdns').attr('id','IDdns'+stt).attr('name','IDdns'+stt).attr('rel',stt);
		step.children('td').children('input.delete').attr('name','delete'+stt);
		step.children('td').children('select').attr('id','dnstype_'+stt).attr('name','type'+stt).attr('rel',stt).val(0).removeAttr('disabled');
		step.children('td').children('img').attr('ShowPopup',stt).attr('id','dnsimg_'+stt);
		step.children('td').children('input.dnstitle_').attr('id','dnstitle_'+stt).attr('name','title'+stt);
		step.children('td').children('input.priority').attr('name','priority'+stt);		
		step.children('td').children('input.protocol').attr('name','protocol'+stt);
		step.children('td').children('input.weight').attr('name','weight'+stt);
		step.children('td').children('input.portnumber').attr('name','portnumber'+stt);		
		step.children('td').children('input.address').attr('name','address'+stt);		
		step.children('td').children('input.priority').attr('name','priority'+stt).val('10');
		step.children('td.stt').text(stt+1);
		step.children('td').children('input:last').val('10');
		step.children('td').children('img').hide(0);	
		step.children('td').children('a#linkenable:first').trigger("click");
		step.children('td').children('input').val('').removeAttr('disabled');
		step.appendTo(ul);		
	}
	if(($n<2 && $flag)) step.children('td').children('input.host:first').select();
	else if($flag || $n>1) $("input.host[value='']:first",ul).focus();	
	$numhost = $numhost+$n;
	//$('#numhost').val($numhost);	
	$('#numhost').val(parseInt($('tr.record:last',ul).children('td:first').text())+1);
	$("input#addrecord").removeAttr('disabled').html($("input#addrecord").attr('title'));	
	
	
	return false;
}
jQuery(function($)
{
	$("a#linkenable:last",$("ol#process_step",document.body)).trigger("click");
	$("a#addrecord").bind("click",function(event)
	{
		event.preventDefault();
		AddRecord(true);
		$("select.recordtype:last",document.body).trigger("change");
	})
	$("input.host:last").live("click",function()
	{
		$("select.recordtype:last",document.body).trigger("change");
		AddRecord(false);
	})
	$("input.address:last").live("keydown",function(event)
	{
		if(event.keyCode==9)
		{			
			$("select.recordtype:last",document.body).trigger("change");
			AddRecord(false);			
		}
	})
	$("select.recordtype",document.body).live("change",function()
	{
		ChangeTypeDNS($(this).attr('rel'));
	});
	$("img.imageshowpopup",document.body).live("click",function()
	{
		ShowPopupDNS($(this).attr('showpopup'));
	});	
	$("a#linkenable").live("click",function(event)
	{
		event.preventDefault();
		var $last = $(this).parent('td').parent('tr');
		$last.children('td').children('select').removeAttr('disabled');
		$last.children('td').children('input').removeAttr('disabled');
		$last.children('td').children('a#linkenable').hide(0);
		$last.children('td').children('a#linkdisable').show(0);
		return false;
	})
	$("a#linkdisable").live("click",function(event)
	{
		event.preventDefault();
		var $last = $(this).parent('td').parent('tr');
		$last.children('td').children('select').attr('disabled','disabled');
		$last.children('td').children('input').attr('disabled','disabled');
		$last.children('td').children('a#linkenable').show(0);
		$last.children('td').children('a#linkdisable').hide(0);
		return false;
	})
	$("a.remove").live("click",function(event)
	{
		event.preventDefault();
		allrecord = $('table#process_step',document.body).children('tbody').children('tr');		
		var $last = $(this).parent('td').parent('tr');		
		var $obj = $('#listdelete');
		var $v = $last.children('td').children('input.IDdns').val();
		if($v.length>0) $obj.val($obj.val()+','+$v);
		$find = $last.index();
		$host = $last.children('td').children('input.host').val();
		$address = $last.children('td').children('input.address').val();
		if($host != '' || $address != '')
		{
			var $list = $("input.host[type=text]",$("table#process_step",document.body));
			if($list.length>0 && $list.length==1)
			{
				AddRecord(false);
				del = $last.remove();
				$("input.host:first").focus();
			}else
			{
				del = $last.remove();
				var ul = $('table#process_step',document.body);		
				$('#numhost').val(parseInt($('tr.record:last',ul).children('td:first').text())+1);
				//$('#numhost').val(parseInt(ul.children('tr.record:last').children('td').children('input.IDdns:first').attr('rel'))+1);
			}
		}
		else
		{
			var $list = $("input.host[type=text]",$("table#process_step",document.body));	
			if($list.html()==null) $last.remove();
			if($list.length>1)
			{
				del = $last.remove();
				var ul = $('table#process_step',document.body);			
				//$('#numhost').val(parseInt(ul.children('tr.record:last').children('td').children('input.IDdns:first').attr('rel'))+1);
				$('#numhost').val(parseInt($('tr.record:last',ul).children('td:first').text())+1);
			}
		}
		return true;		
	})
});
function isIP(ipaddress) 
{
 if(/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress))
  {
    return true;
  }   
  return false;
}
function isDomain(domain)
{
	if(domain.indexOf('_')!=-1 || domain.indexOf('..')!=-1 || domain.indexOf('--')!=-1) return false;
	return /^[a-zA-Z0-9][a-zA-Z0-9\-\.]{0,62}[.][a-zA-Z]{2,6}$/i.test(domain);
}
function isDomainMX(domain)
{
	if(domain.indexOf('_')!=-1 || domain.indexOf('..')!=-1 || domain.indexOf('--')!=-1) return false;
	return /^[a-zA-Z0-9][a-zA-Z0-9\-\.]{0,62}[.][a-zA-Z]{2,20}$/i.test(domain);
}
function CheckFormDNS($domainidn)
{
	var $domain 		= $domainidn;
	$TypeName 			= new Array('A','CNAME','MX','URL REDIRECT','TXT','URL FRAME');
	// Bat loi cau hinh record bang javascript here
	var $container 		= $("table#process_step",document.body);
	$typelist			= $("select.recordtype:enabled",$container);
	$last 				= $("select.recordtype:last",$container).attr("rel");
	$("tr.record",$container).removeClass('red').removeClass('red2');
	$iswarning  		= false;
	$tmp_icontainer 	= null;
	jQuery.each($typelist,function($k,$v)
	{		
		$icontainer		= $(this).parents("tr.record:first");
		var $type		= parseInt($(this).val());		
		$address 		= $("input.address",$icontainer).val().trim();		
		
		$host 			= $("input.host",$icontainer).val().toLowerCase().trim();	
		$prio 			= $("input.priority",$icontainer).val().trim();	
		$islast 		= ($last==$(this).attr('rel')); // Is last record		

		
		$flagbreak 		= false;
		// Check Double Record
		if($type==1)
		{
			// Type CNAME
			$ocontainer = $icontainer.siblings("tr.record");
			$.each($ocontainer,function()
			{
				var $ccontainer	= $(this);
				$ctype 			= $("select.recordtype",$ccontainer).val().trim();
				$caddress 		= $("input.address",$ccontainer).val().trim();
				$chost 			= $("input.host",$ccontainer).val().toLowerCase().trim();
				$cprio 			= $("input.priority",$ccontainer).val().trim();	
				$dk = (($chost==$host && $ctype=='1') || ($chost==$host && $ctype=='0') || ($chost==$host && $ctype=='3') || ($chost==$host && $ctype=='5'));
				if($dk)
				{
					$flagbreak 	= true;					
					$ccontainer.addClass("red2");
					$icontainer.addClass("red2");
					alert("Record xung đột: Host->"+$host+" | Type->A/CNAME | Address->"+$address+" | Prio->"+$prio);
					return false;
				}
			})		
		}else if($type==2)
		{
			// Type MX
			$ocontainer = $icontainer.siblings("tr.record");
			$.each($ocontainer,function()
			{
				var $ccontainer	= $(this);
				$ctype 			= $("select.recordtype",$ccontainer).val().trim();
				$caddress 		= $("input.address",$ccontainer).val().trim();
				$chost 			= $("input.host",$ccontainer).val().toLowerCase().trim();
				$cprio 			= $("input.priority",$ccontainer).val().trim();	
				$dk 			= ($chost==$host && $ctype==$type && $caddress==$address && $cprio==$prio);
				if($dk)
				{
					$flagbreak 	= true;					
					$ccontainer.addClass("red2");
					$icontainer.addClass("red2");
					alert("Record xung đột: Host->"+$host+" | Type->MX | Address->"+$address+" | Prio->"+$prio);
					return false;
				}
			})
		}else if($type==0)
		{
			// Type A
			$ocontainer = $icontainer.siblings("tr.record");
			$.each($ocontainer,function()
			{
				var $ccontainer	= $(this);
				$ctype 			= $("select.recordtype",$ccontainer).val().trim();
				$caddress 		= $("input.address",$ccontainer).val().trim();
				$chost 			= $("input.host",$ccontainer).val().toLowerCase().trim();
				$cprio 			= $("input.priority",$ccontainer).val().trim();	
				$dk 			= (($chost==$host && $ctype=='1') || ($chost==$host && $ctype=='0' && $caddress==$address));
				if($dk)
				{
					$flagbreak 	= true;					
					$ccontainer.addClass("red2");
					$icontainer.addClass("red2");
					alert("Record xung đột: Host->"+$host+" | Type->A/CNAME | Address->"+$address+" | Prio->"+$prio);
					return false;
				}
			})
		}else if($type==7)
		{			
			// Type SRV
			$tcp 			= $("input.protocol",$icontainer).val().trim();	
			$port 			= $("input.portnumber",$icontainer).val().trim();				
			$ocontainer = $icontainer.siblings("tr.record");
			$.each($ocontainer,function()
			{
				var $ccontainer	= $(this);
				$ctype 			= $("select.recordtype",$ccontainer).val().trim();
				$caddress 		= $("input.address",$ccontainer).val().trim();
				$chost 			= $("input.host",$ccontainer).val().toLowerCase().trim();
				$cprio 			= $("input.priority",$ccontainer).val().trim();	
				$ctcp 			= $("input.protocol",$ccontainer).val().trim();	
				$cport 			= $("input.portnumber",$ccontainer).val().trim();	
				$dk 			= ($chost==$host && $ctype==$type && $caddress==$address && $cprio==$prio && $ctcp==$tcp && $cport==$port);
				if($dk)
				{
					$flagbreak 	= true;					
					$ccontainer.addClass("red2");
					$icontainer.addClass("red2");
					alert("Record xung đột: Host->"+$host+" | Type->A/CNAME | Address->"+$address+" | Prio->"+$prio);
					return false;
				}
			})
		}
		else
		{
			// Other Type
			$ocontainer = $icontainer.siblings("tr.record");
			$.each($ocontainer,function()
			{
				var $ccontainer	= $(this);
				$ctype 			= $("select.recordtype",$ccontainer).val().trim();
				$caddress 		= $("input.address",$ccontainer).val().trim();
				$chost 			= $("input.host",$ccontainer).val().toLowerCase().trim();
				$cprio 			= $("input.priority",$ccontainer).val().trim();	
				$dk 			= ($chost==$host && $ctype==$type && $caddress==$address);
				if($dk)
				{
					$flagbreak 	= true;					
					$ccontainer.addClass("red2");
					$icontainer.addClass("red2");
					alert("Record xung đột: Host->"+$host+" | Type->"+$type+" | Address->"+$address+" | Prio->"+$prio);
					return false;
				}
			})
		}
		if($flagbreak)
		{
			return false;
		}	
		
		if(!$islast || ($islast && ($address.length>0 || $host.length>1)))
		{
			$flagbreak 	= false;
			if((($type!=4 && $host.length<1) || ($address.length<1)))
			{
				$flagbreak 	= true;
				$icontainer.addClass("red");
				$("input.host",$icontainer).focus();
				return false;
			}
			var $pattern = new RegExp($domainidn+"[.]?$","i");
			if($type==1 && $host=='@' && ($pattern.test($address))) 
			{
				$flagbreak 	= true;
				$icontainer.addClass("red");
				alert("Không được CNAME đến chính nó");				
				return false;
			}else if($type==6 && ($host=='@' || $host=='www')) 
			{
				$flagbreak 	= true;
				$icontainer.addClass("red");
				alert("Record NS Host không thể là www | @");				
				return false;
			}else if($type==6 && ($host==$address)) 
			{
				$flagbreak 	= true;
				$icontainer.addClass("red");
				alert("Record NS Host Name không thể giống Address");				
				return false;
			}else if($host=='*' && ($type==3 || $type==5))
			{
				$flagbreak 	= true;
				$icontainer.addClass("red");
				alert("Record URL REDIRECT/FRAME Host Name không thể là [*]");			
				return false;
			}
			switch($type)
			{
				case 0:
					if(!isIP($address))
					{
						$icontainer.addClass("red");	
						$("input.address",$icontainer).select();
						$flagbreak = true;
						alert("Record A Address phải là địa chỉ IP.");
						return false;							 
					}
				break;
				case 1:
					$address = $address.replace(/[.]$/ig,'',$address);
					if(isIP($address))
					{
						$flagbreak = true;	
						$icontainer.addClass("red");
						$("input.address",$icontainer).select();
						alert("Record CNAME Address phải là Tên miền.");
						return false;		
									 
					}else if(!isDomain($address))
					{						
						$icontainer.addClass("red");	
						$("input.address",$icontainer).select();
						$flagbreak = true;
						alert("Record CNAME Address nhập Tên miền không hợp lệ.");				 
						return false;
					}
				break;
				case 2:
					$address = $address.replace(/[.]$/ig,'',$address);
					if(isIP($address))
					{
						$flagbreak = true;							
						$icontainer.addClass("red");	
						$("input.address",$icontainer).select();
						alert("Record MX Address phải là tên mail server. Ví dụ: mail.abc.vn");	
						return false;									 
					}else if(!isDomainMX($address))
					{						
						$icontainer.addClass("red");	
						$("input.address",$icontainer).select();
						$flagbreak = true;
						alert("Record MX Address nhập tên mail server phải là tên miền hợp lệ.");				 
						return false;
					}
				break;
				case 3:
				case 5:
					
					$tmpaddress		= $address.replace(/^[a-z]{2,5}[:][\/][\/]/ig,"");
					$tmpaddress		= $tmpaddress.replace(/\/+$/ig,"");
					$tmpaddress		= $tmpaddress.trim();
					$domain_temp	= ($host+'.'+$domain).trim();
					if($tmpaddress.lastIndexOf(".")==-1 || $tmpaddress.substr(-1)=='.')
					{
						$icontainer.addClass("red");	
						$("input.address",$icontainer).select();
						$flagbreak = true;
						alert("Record Redirect/ URL Frame Address nhập Tên miền không hợp lệ.");				 
						return false;
						
					}else if($tmpaddress == $domain_temp || $host==$domain)
					{
						$flagbreak = true;							
						$icontainer.addClass("red");
						$("input.address",$icontainer).select();	
						alert("Bạn không được phép Redirect/ URL Frame về chính domain hiện tại");		
						return false;							 
					}
				break;
				case 4:
					if($host == "www")
					{
						$flagbreak = true;						
						$icontainer.addClass("red");	
						alert("Record TXT Hostname không thể là giá trị www.");	
						return false;				
					}
				break;				
			}
		}	
		if($host=='@' && $type==1)
		{
			$iswarning = true;
			$tmp_icontainer = $icontainer;
		}
	})
	if($iswarning && !$flagbreak)
	{
		$tmp_icontainer.addClass('red');
		alert("(*) CẢNH BÁO:\nRECORD ĐƯỢC CẤU HÌNH LÀ @ - CNAME THÌ CÁC RECORD KHÁC SẼ KHÔNG CÓ TÁC DỤNG!");		
	}
	if($flagbreak) return false;
	return true;
}

function ConfirmSave($domainidn)
{
	if($('#address0').val() == '')
	{
		$('#address0').removeAttr('disabled');
		$('#address0').focus();
		alert(Error_2);		
		return false;
	}
	if($('#address1').val() == '')
	{
		$('#address1').removeAttr('disabled');
		$('#address1').focus();
		alert(Error_3);		
		return false;
	}
	var $flagcheck = CheckFormDNS($domainidn);
	if(!$flagcheck) return false;
	
	return confirm(Error_4);	
}
jQuery(function($)
{
	$(window).bind("resize",function()
	{
		$("div.cover").trigger("customresize");
	})
	$(window).load(function() 
	{ 
		$("div.cover").trigger("customresize");
	});
	$("div.cover").bind("customresize",function()
	{		
		$xpos = $(this).offset();	
		if($xpos.top<100)
		{ 
			$(this).css({"margin-top":"0px","top":"150px"});
		}
	})
	$(".animate",document.body).bind("mouseenter",function() 
	{ 
		$(this).clearQueue(); 
		$(this).stop(); 
		$(this).fadeTo('fast', 0.75); 
	}) 
	$(".animate",document.body).bind("mouseleave",function() 
	{ 
		$(this).clearQueue(); 
		$(this).stop(); 
		$(this).fadeTo('fast', 1.0);
	})
	$(".animated",document.body).live("mouseenter",function() 
	{ 
		$(this).clearQueue(); 
		$(this).stop(); 
		$(this).css({"color":"#FFC"});
		$(this).fadeTo('fast', 1.0);
	}) 
	$(".animated",document.body).live("mouseleave",function() 
	{ 
		$(this).clearQueue(); 
		$(this).stop(); 
		$(this).fadeTo('fast', 0.75);
	})
	
	$("input.whois").bind("change",function(){
		var $info = $(this).attr("id").split("_");
		$name = $info[0];
		$("#"+$name+"_change").val("1");
	})

})